import React, {useEffect, useState} from 'react';
import ReactECharts from 'echarts-for-react';
import {$getSexNum} from "../../api/Demoapi";

const PieChart = () => {
    const [data,setData]=useState({});
    const getSexNum=async ()=>{
       const response = await $getSexNum({});
       setData(response.data);
    }
    useEffect(()=>{
        getSexNum();
    },[])
    const option = {
        tooltip: {
            trigger: 'item'
        },
        legend: {
            orient: 'vertical',
            left: 'left'
        },
        series: [
            {
                name: 'Access From',
                type: 'pie',
                radius: '50%',
                data: [
                    { value: data.MaleCount, name: '男' },
                    { value: data.FemaleCount, name: '女' },
                ],
                emphasis: {
                    itemStyle: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }
            }
        ]
    };

    return <ReactECharts option={option} style={{ height: '300px' }} />;
};

export default PieChart;
